<?php
	session_start();
	require("connect.php");
	$link = connect_APO();
	require("check.php");
	is_admin();
	require("header+logoutB.php");
	headerL();
	
	$midweek_name = $_GET['midweek'];
	if($midweek_name !== NULL){
		$sql = sprintf("SELECT * From midweeks where Name = '$midweek_name'");
		$result = mysql_query($sql);
		$row = 	mysql_fetch_array($result);
		$midweek_old_Stime = $row["StartTime"];
		$midweek_old_Etime = $row["EndTime"];
		$midweek_old_Day = $row["Day"];
		$midweek_old_Credit = $row["Credit"];
		$midweek_old_Leader1 = $row["Leader1"];
		$midweek_old_Leader2 = $row["Leader2"];
		$midweek_old_MaxPeople = $row["MaxPeople"];
		$midweek_old_Location = $row["Location"];
		$midweek_old_Meeting = $row["MeetinPlace"];
		$midweek_old_SName = $row["SName"];
	}
	
	$sql = sprintf("SELECT FName,LName,ID From users ORDER BY FName,LName");
	$result = mysql_query($sql);
	
	$num_people = 0;
	while($row = mysql_fetch_array($result)){
		$num_people +=1;
		$FNames[] = $row["FName"];
		$LNames[] = $row["LName"];
		$IDs[] = $row["ID"];
	}

	$selectL1 = "<select name='midweekTLeader1'><option selected='yes' value='none'> None ";
	$selectL2 = "<select name='midweekTLeader2'><option selected='yes' value='none'> None ";
					
	for($i = 0; $i<$num_people; $i +=1){
		$selectL1 .= "<option value='".$IDs[$i]."'>".$FNames[$i]." ".$LNames[$i]."</option>";
		$selectL2 .= "<option value='".$IDs[$i]."'>".$FNames[$i]." ".$LNames[$i]."</option>";
	}
	
		
	$selectL1 .= "</select>";
	$selectL2 .= "</select>";
	
	echo "<html>

<body>

<font class='mainFont'>
	<center>
		<div id='midweekTable'>	
		<div id='links'>
			<div id='backLink'> <A href='midweeks.php'>Back to Midweek Administration</A></div>
		</div>
			<b class='b1f'></b><b class='b2f'></b><b class='b3f'></b><b class='b4f'></b>
			<div id='midweekTForm'>
			<div class='contentf'>
			<form action='addMidToDB.php' method='post'>	
				<div id='midweekTName'><label for='midweekTName'>Midweek Name: </label>
				<input type='text' name='midweekTName' value='$midweek_old_SName'></div>
				<div id='midweekTDay'>
					<label for='midweekTDay'>Day of the week: </label>
					<select name='midweekTDay'> 
						<option ";
						if($midweek_old_Day == 'Sun'){
								echo "selected='yes'";
						} else if($midweek_old_Day != null)
							echo "selected='yes'";
						echo " value='Sun'> Sun </option>
						<option ";
						if($midweek_old_Day == 'Mon')
								echo "selected='yes'";
						echo " value='Mon'> Mon </option>
						<option ";
						if($midweek_old_Day == 'Tue')
								echo "selected='yes'";
						echo " value='Tue'> Tue </option>
						<option";
						if($midweek_old_Day == 'Wed')
								echo "selected='yes'";
						echo " value='Wed'> Wed </option>
						<option ";
						if($midweek_old_Day == 'Thu')
								echo "selected='yes'";
						echo " value='Thu'> Thu </option>
						<option ";
						if($midweek_old_Day == 'Fri')
								echo "selected='yes'";
						echo " value='Fri'> Fri </option>
						<option ";
						if($midweek_old_Day == 'Sat')
								echo "selected='yes'";
						echo" value='Sat'> Sat </option>
					</select>
				</div>
				<div id='midweekTTime'>
					<div id='midweekTSTime' style='padding-right:40;'><label for='midweekTSTime'>Start Time: </label>
						<input type='text' name='midweekTSTimeHR' size='2' maxlength='2' value='09'> : 
						<input type='text' name='midweekTSTimeMIN' size='2' maxlength='2' value='00'> 
						<select name='midweekTSTimeM'> 
							<option selected='yes' value='AM'> AM </option>
							<option value='PM'> PM </option>
						</select>
					</div>
					<div id='midweekTETime'>
						<label for='midweekTETime'>End Time: </label>
						<input type='text' name='midweekTETimeHR' size='2' maxlength='2' value='10'> : 
						<input type='text' name='midweekTETimeMIN' size='2' maxlength='2' value='00'> 
						<select name='midweekTETimeM'> 
							<option selected='yes' value='AM'> AM </option>
							<option value='PM'> PM </option>
						</select>
					</div>
				</div>
				<div id='midweekTLeaders'>
					Please select the leaders of this midweek (if only one leader, use the first slot).
					<div id='midweekTLeader1'> Leader: ".$selectL1."
					</div>
					<div id='midweekTLeader2'> Leader: ".$selectL2."
					</div>
				</div>
				<div id='midweekTCredit'>
					<label for='midweekTCredit'>Midweek Credit: </label>
					<input type='text' name='midweekTCredit' size='2' maxlength='2' value='1'>
				</div>
				<div>
					<div id='midweekTSlots'>
						<label for='midweekTMSlots'>Max Slots: </label>
						<input type='text' name='midweekTMSlots' size='2' maxlength='2' value='1'>
					</div>
				</div>
				<div id='midweekTMeet'>
					<label for='midweekTMeet'>Meeting Location: </label>
					<input type='text' name='midweekTMeet' value='Bonnycastle'>
				</div>
				<div id='midweekTLocation'>
					<label for='midweekTLocation'>Midweek Location: </label>
					<input type='text' name='midweekTLocation'>
				</div>
				<br>
				<div id='addMidButton'>
					<input type='hidden' name='".$midweek_name."'/>
					<input type='submit' value='Submit' class='loginButton'/>
					<input type='reset' class='loginButton'/>
			</form>
			</div>
			</div>
			</div>
	  <b class='b4f'></b><b class='b3f'></b><b class='b2f'></b><b class='b1f'></b>
		</div>
	</center>
</font>
</body>
</head>
</html>";

	require("footer.php");
	footer();
?>